using System.Linq;
using Magiq.Query;

namespace Magiq.Databases.Query
{
    public class QueryInfoDatabaseQueryStrategy<T, TChild> : IQueryStrategy<TChild>, IDatabaseBasedExecution where T : class 
    {
        private readonly QueryInfo<T,TChild> queryInfo;

        public QueryInfoDatabaseQueryStrategy(IOrmAdapter ormAdapter, QueryInfo<T, TChild> queryInfo)
        {
            OrmAdapter = ormAdapter;
            this.queryInfo = queryInfo;
        }

        #region IDatabaseBasedExecution Members

        public IOrmAdapter OrmAdapter { get; private set; }

        #endregion

        #region IQueryStrategy<T> Members

        public IQueryable<TChild> Execute()
        {
            return OrmAdapter.GetQueryableFrom(queryInfo);
        }

        #endregion
    }
}